# Maintainer: Alexey Pavlov <alexpux@gmail.com>

_realname=libc++
pkgbase=mingw-w64-${_realname}
pkgname="${MINGW_PACKAGE_PREFIX}-${_realname}"
pkgver=3.5.0
pkgrel=1
pkgdesc='A new implementation of the C++ standard library, targeting C++11.'
url='https://libcxx.llvm.org/'
license=('custom:University of Illinois/NCSA Open Source License')
arch=('any')
# gcc-libs needed for libgcc_s, because mingw-w64 doesn't use a pure compiler-rt clang
depends=("${MINGW_PACKAGE_PREFIX}-gcc-libs"
        #"${MINGW_PACKAGE_PREFIX}-libc++abi"
        )
makedepends=("${MINGW_PACKAGE_PREFIX}-clang"
             "${MINGW_PACKAGE_PREFIX}-cmake")
source=(https://releases.llvm.org/$pkgver/libcxx-${pkgver}.src.tar.xz{,.sig})
sha256sums=('8045da845a63e50c201939eda8290d45e5752a9385d4d626214300d4a4d0b1c0'
            'SKIP')
#install=${pkgname}.install

prepare() {
  cd ${srcdir}/libcxx-${pkgver}.src
}

build() {
  [[ -d ${srcdir}/build-${MINGW_CHOST} ]] && rm -rf ${srcdir}/build-${MINGW_CHOST}
  mkdir -p ${srcdir}/build-${MINGW_CHOST} && cd ${srcdir}/build-${MINGW_CHOST}

  export CXX="${MINGW_PREFIX}/bin/clang++"
  export CC="${MINGW_PREFIX}/bin/clang"
  ${MINGW_PREFIX}/bin/cmake.exe \
    -G"MSYS Makefiles" \
    -DCMAKE_INSTALL_PREFIX:PATH=${pkgdir}${MINGW_PREFIX} \
    -DCMAKE_BUILD_TYPE=Release \
    ../libcxx-${pkgver}.src
  make
}

package() {
  cd "${srcdir}/build-${MINGW_CHOST}"
  make -j1 DESTDIR="$pkgdir" install
}
